package com.webproject.action.sysManager;

import java.util.List;

import com.webproject.core.BaseAction;
import com.webproject.entity.sysManager.SysMenu;
import com.webproject.entity.sysManager.User;
import com.webproject.service.sysManager.SysManagerService;
import com.webproject.service.sysManager.UserManagerService;

/**
 * 登出，退出，系统菜单查询
 * @author lijiang
 *
 */
public class SysManagerAction extends BaseAction {
	private SysManagerService sysManagerService;
	private UserManagerService userManagerService;
	public void setUserManagerService(UserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}

	public void setSysManagerService(SysManagerService sysManagerService) {
		this.sysManagerService = sysManagerService;
	}
	private List<SysMenu> menus;
	
	private String msg;
	private boolean success;
	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public List<SysMenu> getMenus() {
		return menus;
	}

	public void setMenus(List<SysMenu> menus) {
		this.menus = menus;
	}

	public String login(){
		String loginName=getRequest().getParameter("loginName");
		String pwd=getRequest().getParameter("pwd");
		User user=new User();
		user.setLoginName(loginName);
		user.setPwd(pwd);
		User queryUser=userManagerService.queryUser(user);
		if(queryUser!=null){
			getSession().setAttribute("user", queryUser);
			return SUCCESS;
		}else{
			return "input";
		}
	}
	public String loginOut(){
		getSession().removeAttribute("user");
		return SUCCESS;
	}
	public String sysMenu(){
		String roleId=getRequest().getParameter("roleId");
		menus=sysManagerService.querySysMenu(roleId);
		return SUCCESS;
	}
	
	public String editPwd(){
		User user=(User) getSession().getAttribute("user");
		User queryUser=userManagerService.queryUser(user);
		String oldPwd=getRequest().getParameter("oldpwd");
		String newPwd=getRequest().getParameter("newpwd");
		if(oldPwd.equals(queryUser.getPwd())){
			//修改口令
			queryUser.setPwd(newPwd);
			userManagerService.updateUser(queryUser);
			msg="修改成功";
			success=true;
		}else{
			msg="原始口令出错";
			success=false;
		}
		return SUCCESS;
	}
	public String sysMenuByUser(){
		User user=(User) getSession().getAttribute("user");
		menus=sysManagerService.querySysMenuByUser(user);
		return SUCCESS;
	}
	public String enterUserManager(){
		
		return SUCCESS;
	}
	public String enterLogManager(){
		
		return SUCCESS;
	}
	public String enterRoleManager(){
		
		return SUCCESS;
	}
	public String enterBuilding(){
		return SUCCESS;
	}
	public String enterRoomInfo(){
		
		return SUCCESS;
	}
	public String enterRoom(){
		return SUCCESS;
	}
	public String enterHousehold(){
		return SUCCESS;
	}
	public String enterEquipment(){
		return SUCCESS;
	}
	public String enterEmployee(){
		return SUCCESS;
	}
	public String enterEmployeeWorkPlan(){
		return SUCCESS;
	}
	public String enterEmployeeAttence(){
		return SUCCESS;
	}
	public String enterEmployeeSalary(){
		return SUCCESS;
	}
	public String enterEquipmentType(){
		return SUCCESS;
	}
	public String enterComplain(){
		return SUCCESS;
	}
	public String enterCarPosition(){
		return SUCCESS;
	}
	public String enterStopCar(){
		return SUCCESS;
	}
	public String enterStopCarCost(){
		return SUCCESS;
	}
	public String enterWaterEle(){
		return SUCCESS;
	}
	public String enterMonthRate(){
		return SUCCESS;
	}
}
